package com.hzncc.scaffold.service.impl;

import cn.hutool.core.date.DateUtil;
import com.hzncc.scaffold.core.ResultT;
import com.hzncc.scaffold.entity.Other.Job;
import com.hzncc.scaffold.mapper.JobMapper;
import com.hzncc.scaffold.service.JobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 职位表 服务实现类
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobService {

    @Autowired
    JobService jobService;

    @Override
    public ResultT saveJob(Job job) {
        boolean save = jobService.save(job);
        if (save) {
            return ResultT.success("新增成功");
        } else {
            return ResultT.fail("新增失败");
        }
    }

    @Override
    public ResultT updateJob(Job job) {
        boolean update = jobService.updateById(job);
        if (update) {
            return ResultT.success("修改成功");
        } else {
            return ResultT.fail("修改失败");
        }
    }

    @Override
    public ResultT stayAtTop(Integer jobId, Integer stayAtTop) {
        if (jobService.getById(jobId) != null) {
            Job job = jobService.getById(jobId);
            if (stayAtTop == 1 || stayAtTop == 0) {
                job.setStayAtTop(stayAtTop);
                job.setSortTime(DateUtil.now());
            } else {
                return ResultT.fail("数据错误");
            }
            boolean update = jobService.updateById(job);
            if (update) {
                if (stayAtTop == 1) {
                    return ResultT.success("置顶成功");
                } else {
                    return ResultT.success("取消置顶成功");
                }
            } else {
                return ResultT.fail("置顶失败");
            }
        } else {
            return ResultT.fail("数据错误");
        }
    }
}
